Skip to content

Conversation

@t-reents
Copy link
Collaborator

@t-reents t-reents commented Oct 23, 2025

Explanation in the commit message:

This PR adds support to run fixed spin moment calculations, i.e., enabling the user to specify the total magnetization of the cell that is kept during the calculation.

Moreover, since this is a new feature that is not supported by all the plugins in the beginning (or maybe in general), this PR also introduces the concept of additional optional features in the common workflows. Once the plugin developers add support for that feature, it will be enabled and is ready to use.

In addition to just supporting fixed total magnetization in the relaxations, we also add a workflow to calculate the energy as a function of the (fixed) magnetization. This is very similar to the previous Equation of state.

The idea of the optional features is that a common workflow can define a set of optional features that are in principle supported, e.g., _optional_features in the CommonRelaxInputGenerator, and the specific implementation has to define and override which of those features are actually supported, see _supported_optional_features in QuantumEspressoCommonRelaxInputGenerator and in the test below.

@mbercx pinging you here for a review as I remember that you were also again interested in the common workflows. Please note that this is a feature that we need for our current project for the AE verification. Hence, we were initially thinking to just do it in a very hacky way. This is just to say that I tried to find a general solution here that can be expanded to other workflows in the future, while still keeping it practical for our current project.
Let me know if you have any major concerns/comments. Otherwise, @giovannipizzi and me would be keen on proceeding 😄

This PR adds support to run fixed spin moment calculations, i.e.,
enabling the user to specify the total magnetization of the cell that is
kepy during the calculation.

Moreover, since this is a new feature that is not supported by all the
plugins in the beginning (or maybe in general), this PR also introduces
the concept of additional optional features in the common workflows.
Once the plugin developers add support for that feature, it will be
enabled and is ready to use.
@t-reents
Copy link
Collaborator Author

First an example to test the previous EOS workflow with fixed magnetization:

%load_ext aiida
%aiida

from aiida.orm import List, Dict
from aiida.engine import submit, run
from aiida_common_workflows.plugins import WorkflowFactory
from aiida_common_workflows.common import ElectronicType, RelaxType, SpinType


cls = WorkflowFactory('common_workflows.eos')

engines = {
      'relax': {
          'code': 'qe-7.3-gf-pw@thor',
          'options': {
            'resources': {
                'num_machines': 1,
                'num_mpiprocs_per_machine': 48,       
            },
            'queue_name': 'short',
            'max_wallclock_seconds': int(900),}
            }
  }

structure = 

inputs = {
    'structure': structure,
    'scale_count': Int(3),
    'generator_inputs': {  # code-agnostic inputs for the relaxation
        'engines': engines,
        'protocol': 'fast',
        'relax_type': RelaxType.NONE,
        'spin_type': SpinType.COLLINEAR,
        'fixed_total_cell_magnetization': 2.0,
    },
    'sub_process_class': 'common_workflows.relax.quantum_espresso',  # the relaxation workflow to use
}

run(cls, **inputs)

and for the energy vs. magnetization:

energy_magnetization = WorkflowFactory('common_workflows.em')

inputs = {
    'structure': structure,
    'fixed_total_magnetizations': [0.5, 0.53, 0.56, 0.59, 0.62, 0.65, 0.68, 0.71],
    'generator_inputs': {  # code-agnostic inputs for the relaxation
        'engines': engines,
        'protocol': 'fast',
        'relax_type': RelaxType.NONE,
        'spin_type': SpinType.COLLINEAR,
    },
    'sub_process_class': 'common_workflows.relax.quantum_espresso',  # the relaxation workflow to use
}

wc = submit(energy_magnetization, **inputs)

and finally, to test the optional feature logic:

RelaxWorkChain = WorkflowFactory('common_workflows.relax.quantum_espresso')
print(RelaxWorkChain.get_input_generator().get_optional_features())
print(RelaxWorkChain.get_input_generator().get_supported_optional_features())

RelaxWorkChain = WorkflowFactory('common_workflows.relax.siesta')
print(RelaxWorkChain.get_input_generator().get_optional_features())
print(RelaxWorkChain.get_input_generator().get_supported_optional_features())

# Outputs:
# {<OptionalRelaxFeatures.FIXED_MAGNETIZATION: 'fixed_total_cell_magnetization'>}
# {<OptionalRelaxFeatures.FIXED_MAGNETIZATION: 'fixed_total_cell_magnetization'>}
# {<OptionalRelaxFeatures.FIXED_MAGNETIZATION: 'fixed_total_cell_magnetization'>}
# set()

@t-reents
Copy link
Collaborator Author

@mbercx I fixed the updated protocols in AiiDA-QE here: 41d27ff

This was mainly to see whether this fixes the tests (it does). Either we remember to merge this PR with at least two commits (the actual changes and the protocol updates) or I move it to a separate PR

@t-reents t-reents requested a review from mbercx October 23, 2025 16:44
@mbercx
Copy link
Member

mbercx commented Oct 23, 2025

Thanks @t-reents! I haven't looked into the common workflows in quite some time, so would have to get an overview of the codebase again before being able to do a proper review. Right now, I don't think I can add another project to my plate.

So feel free to go ahead without me signing off on things with @giovannipizzi! Maybe once I'm back in Switzerland I can dedicate some proper time to this package again, it definitely has a lot of potential. :)

Copy link
Collaborator

@bosonie bosonie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @t-reents, and nice t meet you! After a chat with @giovannipizzi, we agreed I could have a look at this PR. Hopefully it speeds up the work on your side and helps me to remember a bit about this nice project. I left you some comments! Let me know if you agree.

…an effective magnetic field based on the difference between the fermi energy of the spin-up and spin-down channel
@t-reents
Copy link
Collaborator Author

t-reents commented Nov 3, 2025

Hi @bosonie ! Indeed, nice to meet you and thanks a lot for having a look at this PR! As you could already see/read, I agreed with all your comments.

  • 3ee6052 addresses the points that you highlighted (except for the module docstring in em.py. I moved it to the next commit by accident)
  • 66c3ed2 Here, I also added the fermi energies to the output. This is something that we would need as well (in order to calculate an effective field). Giovanni and me discussed and agreed to explicitly define separate outputs for the fermi energy (non-collinear and non-magnetic case) and the fermi energy for the spin-up and down channel, in case of collinear magnetism. This was still a local change (sorry). It would be great if you can have a quick look again. One additional change, I also added the new input to the documentation.
  • 234333d Just very briefly to fix RtD

Thanks again for the helpful review, it speeds up our work! As outlined above, I incorporated the changes and added (some small) additional ones. If you find the time, your final feedback would be greatly appreciated, so that we can get this merged.

Copy link
Collaborator

@bosonie bosonie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @t-reents. All good and I approve the PR. However I kindly ask you to open two new issues, so we do not forget about two related points:

  1. The documentation of the new em workchain.
  2. The implementation of the fermi energy output and, when applicable, the fixed_total_cell_magnetization input for all the other plugins.

Bye!

@t-reents
Copy link
Collaborator Author

t-reents commented Nov 4, 2025

Thanks a lot @bosonie ! Yes, those were the missing/future aspects I was also thinking about.

@t-reents t-reents merged commit 8a70baf into aiidateam:master Nov 4, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants